﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;


namespace SportingGoodsExhibitionSystem
{
    /// <summary>
    /// MainMenu.xaml 的交互逻辑
    /// </summary>
    ///  
    public partial class MainMenu : Window
    {
        
        string strCon = Properties.Resources.strCON;
        MainWindow mw = new MainWindow();
        public MainMenu()
        {
            InitializeComponent();
        }
        public int num;
        public MainMenu(string userName , int num)
        {
            InitializeComponent();
            label.Content = "当前用户："+ userName;
            this.num = num;
        }
        
        private void btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            this.frame.Navigate(new Uri(btn.Tag.ToString() + ".xaml", UriKind.Relative));
;
        }
       
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            int sta = 0;
            SqlCommand cmd = new SqlCommand("update [studentInfo] set studentStatus=@num where studentNumber=@id", con);
            cmd.Parameters.Add("@id", SqlDbType.VarChar, 50).Value = num;
            cmd.Parameters.Add("@num", SqlDbType.VarChar, 50).Value = sta;
            cmd.ExecuteNonQuery();
            con.Close();
            this.Close();

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.frame.Navigate(new Uri("StudentInfo" + ".xaml", UriKind.Relative));
        }

       

        private void Window_Closed(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            int sta = 0;
            SqlCommand cmd = new SqlCommand("update [studentInfo] set studentStatus=@num where studentNumber=@id", con);
            cmd.Parameters.Add("@id", SqlDbType.VarChar, 50).Value = num;
            cmd.Parameters.Add("@num", SqlDbType.VarChar, 50).Value = sta;
            cmd.ExecuteNonQuery();
            con.Close();
            this.Close();
        }
    }
}
